package handling

import client.MapleClient
import configs.ServerConfig
import constants.ServerConstants
import handling.cashshop.handler.BuyCashItemHandler
import handling.cashshop.handler.CashShopOperation
import handling.cashshop.handler.CouponCodeHandler
import handling.channel.handler.*
import handling.login.handler.*
import handling.opcode.RecvPacketOpcode
import handling.world.WorldFindService
import org.apache.logging.log4j.LogManager
import tools.MaplePacketCreator
import tools.data.input.SeekableLittleEndianAccessor
import tools.packet.LoginPacket

class HandlePacket {

    private val log = LogManager.getLogger()

    @Throws(Exception::class)
    fun handlePacket(header: RecvPacketOpcode, slea: SeekableLittleEndianAccessor, c: MapleClient, type: ServerType) {
        when (header) {
            RecvPacketOpcode.PONG -> c.pongReceived()
            RecvPacketOpcode.STRANGE_DATA -> {
                // Does nothing for now, HackShield's heartbeat
            }
            RecvPacketOpcode.CLIENT_AUTH -> {
                slea.skip(1)
                val clientfile = slea.readInt()
                var checkfile: Int
                checkfile = (clientfile shr 5 shl 5) + ((clientfile and 0x1F shr 3 xor 2 shl 3) + (7 - (clientfile and 7)))
                checkfile = checkfile or (clientfile shr 7 shl 7)
                checkfile -= 2
//                c.announce(MaplePacketCreator.getClientAuthentication(checkfile));
            }
            RecvPacketOpcode.CLIENT_ERROR // 客户端发送过来的错误信息
            -> ClientErrorLogHandler.handlePacket(slea, c)
            RecvPacketOpcode.CLIENT_FAIL // 客户端失败错误信息
            -> PacketErrorHandler.handlePacket(slea, c)
            RecvPacketOpcode.REQUEST_CONNECTION -> c.announce(LoginPacket.addConnection())
            RecvPacketOpcode.LOGIN_PASSWORD // 登陆账号密码
            -> LoginPasswordHandler.handlePacket(slea, c)
            RecvPacketOpcode.LICENSE_REQUEST // 许可协议
            -> LicenseRequestHandler.handlePacket(slea, c)
            RecvPacketOpcode.SET_GENDER // 选择性别
            -> SetGenderHandler.handlePacket(slea, c)
            RecvPacketOpcode.CHARACTER_CARDS //更新选择的角色卡
            -> UpdateCharCards.handlePacket(slea, c)
            RecvPacketOpcode.SET_CHAR_CARDS //显示角色卡界面 也就是获取角色卡的数量
            -> ShowCharCards.handlePacket(slea, c)
            RecvPacketOpcode.SET_ACC_CASH //获取帐号点卷信息
            -> ShowAccCash.handlePacket(slea, c)
        //            case SEND_ENCRYPTED:
        //                if (c.isLocalhost()) {
        //                    LoginPasswordHandler.handlePacket(slea, c);
        //                } else {
        //                    c.announce(LoginPacket.getCustomEncryption());
        //                }
        //                break;
        //            case CLIENT_START:
        //            case CLIENT_FAILED:
        //                c.announce(LoginPacket.getCustomEncryption());
        //                break;
        //            case VIEW_SERVERLIST:
        //                if (slea.readByte() == 0) {
        //                    ServerlistRequestHandler.handlePacket(c, false);
        //                }
        //                break;
        //            case REDISPLAY_SERVERLIST:
            RecvPacketOpcode.SERVERLIST_REQUEST // 请求服务器列表
            -> ServerlistRequestHandler.handlePacket(c, true)
            RecvPacketOpcode.CLIENT_HELLO // 连接到服务端
            -> {
                MapLoginHandler.handlePacket(slea, c, type)

                if (ServerConfig.WORLD_ONLYADMIN && ServerConstants.AUTO_LOGIN) {
                    for (i in 1..2) {
                        if (WorldFindService.getInstance().findChannelByAccId(i) > 0) {
                            continue
                        }
                        c.setTempInfo("admin" + i, "admin", false)
                        LoginPasswordHandler.Login(c)
                        break
                    }
                }
            }
            RecvPacketOpcode.CHARLIST_REQUEST //请求人物列表
            -> CharlistRequestHandler.handlePacket(slea, c)
            RecvPacketOpcode.SERVERSTATUS_REQUEST // 服务器状态
            -> ServerStatusRequestHandler.handlePacket(c)
            RecvPacketOpcode.CHECK_CHAR_NAME // 检查人物名字
            -> CheckCharNameHandler.handlePacket(slea, c)
            RecvPacketOpcode.CREATE_CHAR // 创建人物
            -> CreateCharHandler.handlePacket(slea, c)
            RecvPacketOpcode.CREATE_ULTIMATE // 创建终极冒险家
            -> CreateUltimateHandler.handlePacket(slea, c)
            RecvPacketOpcode.DELETE_CHAR // 删除角色
            -> DeleteCharHandler.handlePacket(slea, c)
            RecvPacketOpcode.PART_TIME_JOB -> PartJobHandler.handlePacket(slea, c)
            RecvPacketOpcode.CHAR_SELECT   // 开始游戏
                , RecvPacketOpcode.CHAR_SELECTED // 创建角色后直接进入
            -> CharSelectedHandler.handlePacket(slea, c)
            RecvPacketOpcode.UPDATE_CHARSLOT -> UpdatePlayerSlots.handlePacket(slea)
            RecvPacketOpcode.RSA_KEY -> {
                c.announce(LoginPacket.getLoginAUTH())
            }
            RecvPacketOpcode.CREATE_CHAR_REQUEST -> CreateCharHandler.getCreatCharAuth(slea, c)
        /*
             * --------------------------------------------------------------------------------------
             * END OF LOGIN SERVER
             * --------------------------------------------------------------------------------------
             */
            RecvPacketOpcode.SEAL_FAMILIAR -> PlayerHandler.sealFamiliar(slea, c, c.player)
            RecvPacketOpcode.CHANGE_CHANNEL // 更换频道
            -> InterServerHandler.ChangeChannel(slea, c, c.player)
            RecvPacketOpcode.PLAYER_LOGGEDIN // 登陆请求
            -> {
                slea.readInt() //V.114新增 [00 00 00 00]
                val playerid = slea.readInt()
                //后面是MAC地址
                InterServerHandler.Loggedin(slea, playerid, c, type)
            }
            RecvPacketOpcode.ENTER_CASH_SHOP // 进入商城
            -> InterServerHandler.enterCS(c, c.player, false)
            RecvPacketOpcode.ENTER_MTS // 进入拍卖
            -> InterServerHandler.EnterMTS(c, c.player)
            RecvPacketOpcode.CHANGE_PLAYER //切换角色
            -> InterServerHandler.ChangePlayer(slea, c)
            RecvPacketOpcode.LOGIN_AUTHKEY -> LoginPasswordHandler.handlerAuthKey(slea, c)
            RecvPacketOpcode.MOVE_PLAYER // 人物移动
            -> PlayerHandler.MovePlayer(slea, c, c.player)
            RecvPacketOpcode.CHAR_INFO_REQUEST -> {
                slea.readInt()
                PlayerHandler.CharInfoRequest(slea.readInt(), c, c.player)
            }
            RecvPacketOpcode.CLOSE_RANGE_ATTACK //近距离攻击
                , RecvPacketOpcode.RANGED_ATTACK //远距离攻击
                , RecvPacketOpcode.MAGIC_ATTACK  //魔法攻击
                , RecvPacketOpcode.SUMMON_ATTACK //召唤兽攻击
                , RecvPacketOpcode.PASSIVE_ENERGY//被动近距离攻击
                , RecvPacketOpcode.CLUSTER_ATTACK
                , RecvPacketOpcode.SPOTLIGHT_ATTACK
                , RecvPacketOpcode.WARLOCK_MAGIC_ATTACK -> PlayerHandler.attackProcessing(slea, c, header)
            RecvPacketOpcode.SPECIAL_MOVE -> PlayerHandler.SpecialMove(slea, c, c.player)
            RecvPacketOpcode.PROFESSION_INFO -> ItemMakerHandler.ProfessionInfo(slea, c, c.player)
            RecvPacketOpcode.CRAFT_DONE -> ItemMakerHandler.CraftComplete(slea, c, c.player)
            RecvPacketOpcode.CRAFT_MAKE -> ItemMakerHandler.CraftMake(slea, c, c.player)
            RecvPacketOpcode.CRAFT_EFFECT -> ItemMakerHandler.CraftEffect(slea, c, c.player)
            RecvPacketOpcode.START_HARVEST -> ItemMakerHandler.StartHarvest(slea, c, c.player)
            RecvPacketOpcode.STOP_HARVEST -> ItemMakerHandler.StopHarvest(slea, c, c.player)
            RecvPacketOpcode.ACT_CHANGE_REACTOR_USEREQUST -> PlayerHandler.ActChangeReactorUseRequst(slea, c, c.player)
            RecvPacketOpcode.MAKE_EXTRACTOR //分解机
            -> ItemMakerHandler.MakeExtractor(slea, c, c.player)
            RecvPacketOpcode.USE_ENCHANTING -> ItemScrollHandler.UseEquipEnchanting(slea, c, c.player)
            RecvPacketOpcode.USE_ARCANE_FORCE_REQUEST -> ItemScrollHandler.UserArcaneForceRequest(slea, c, c.player)
            RecvPacketOpcode.USE_BAG -> ItemMakerHandler.UseBag(slea, c, c.player)
            RecvPacketOpcode.USE_RECIPE -> ItemMakerHandler.UseRecipe(slea, c, c.player)
            RecvPacketOpcode.USE_NEBULITE -> InventoryHandler.UseNebulite(slea, c, c.player)
            RecvPacketOpcode.MOVE_ANDROID -> PlayerHandler.MoveAndroid(slea, c, c.player)
            RecvPacketOpcode.SUB_LITTLEWHITE -> SummonHandler.SubLittleWhite(slea, c.player)
            RecvPacketOpcode.FACE_EXPRESSION -> PlayerHandler.ChangeEmotion(slea.readInt(), c.player)
            RecvPacketOpcode.FACE_ANDROID -> PlayerHandler.ChangeAndroidEmotion(slea.readByte().toInt(), slea.readByte().toInt(), c.player)
            RecvPacketOpcode.TAKE_DAMAGE -> TakeDamageHandler.TakeDamage(slea, c, c.player)
            RecvPacketOpcode.HEAL_OVER_TIME -> PlayerHandler.Heal(slea, c.player)
            RecvPacketOpcode.CANCEL_BUFF -> PlayerHandler.CancelBuffHandler(slea.readInt(), c.player)
            RecvPacketOpcode.MECH_CANCEL -> PlayerHandler.CancelMech(slea, c.player)
            RecvPacketOpcode.USE_HOLY_FOUNTAIN //使用神圣源泉
            -> PlayersHandler.UseHolyFountain(slea, c, c.player)
            RecvPacketOpcode.CANCEL_ITEM_EFFECT -> PlayerHandler.CancelItemEffect(slea.readInt(), c.player)
            RecvPacketOpcode.USE_CHAIR -> PlayerHandler.UseChair(slea, c, c.player)
            RecvPacketOpcode.CANCEL_CHAIR -> PlayerHandler.CancelChair(slea.readShort(), c, c.player)
            RecvPacketOpcode.USE_ITEM_EFFECT //使用商城道具效果
            -> PlayerHandler.UseItemEffect(slea, c, c.player)
            RecvPacketOpcode.WHEEL_OF_FORTUNE //使用未知效果 ------------------- 不确定
            -> {
                //whatever
            }
            RecvPacketOpcode.USE_TITLE_EFFECT //使用称号道具
            -> PlayerHandler.UseTitleEffect(slea.readInt(), c, c.player)
            RecvPacketOpcode.MICRO_BUFF_END_TIME -> PlayerHandler.MicroBuffEndTime(slea, c.player)
            RecvPacketOpcode.USE_ACTIVATE_DAMAGE_SKIN  //使用未知效果 ------------------- 不确定
            -> PlayerHandler.UseActivateDamageSkin(slea, c.player)
            RecvPacketOpcode.USE_ACTIVATE_DAMAGE_SKIN_PREMIUM -> PlayerHandler.SaveDamageSkin(slea, c.player)
            RecvPacketOpcode.USE_SAVE_DAMAGE_SKIN -> PlayerHandler.SaveDamgeSkinEx(slea, c.player)
            RecvPacketOpcode.OBTACLE_ATOM_COLLISION -> {
            }
            RecvPacketOpcode.DEMIANOBJECT_MAKE_ENTER_ACK -> PlayerHandler.DemianObjectMakeEnterAck(slea, c.player)
            RecvPacketOpcode.DEMIANOBJECT_NODE_END -> PlayerHandler.DemianObjectNodeEnd(slea, c.player)
            RecvPacketOpcode.DEMIANOBJECT_ERR_RECREATE -> {
            }
            RecvPacketOpcode.SKILL_EFFECT -> PlayerHandler.SkillEffect(slea, c.player)
            RecvPacketOpcode.SUPER_CANNON_REQUEST -> PlayerHandler.UserSupserCannotRequest(slea, c.player)
            RecvPacketOpcode.QUICK_SLOT -> PlayerHandler.QuickSlot(slea, c.player)
            RecvPacketOpcode.PASSIVE_SKILL_INFO_UPDATE -> PlayerHandler.PassiveskillInfoUpdate(slea, c, c.player)
            RecvPacketOpcode.MESO_DROP -> {
                c.player.updateTick(slea.readInt())
                PlayerHandler.DropMeso(slea.readInt(), c.player)
            }
            RecvPacketOpcode.CHANGE_KEYMAP -> PlayerHandler.ChangeKeymap(slea, c.player)
            RecvPacketOpcode.CHANGE_MAP ->
                if (type == ServerType.商城服务器) {
                    CashShopOperation.LeaveCS(slea, c, c.player)
                } else {
                    PlayerHandler.ChangeMap(slea, c, c.player)
                }
            RecvPacketOpcode.CHANGE_MAP_SPECIAL -> {
                slea.skip(1)
                PlayerHandler.ChangeMapSpecial(slea.readMapleAsciiString(), c, c.player)
            }
            RecvPacketOpcode.USE_INNER_PORTAL -> {
                slea.skip(1)
                PlayerHandler.InnerPortal(slea, c, c.player)
            }
            RecvPacketOpcode.TROCK_ADD_MAP -> PlayerHandler.TrockAddMap(slea, c, c.player)
            RecvPacketOpcode.LIE_DETECTOR -> PlayersHandler.LieDetector(slea, c, c.player, true)
            RecvPacketOpcode.LIE_DETECTOR_SKILL //管理员使用技能进行测谎
            -> PlayersHandler.LieDetector(slea, c, c.player, false)
            RecvPacketOpcode.LIE_DETECTOR_RESPONSE //确定输入的验证码
            -> PlayersHandler.LieDetectorResponse(slea, c)
            RecvPacketOpcode.LIE_DETECTOR_REFRESH //测谎仪图片刷新
            -> PlayersHandler.LieDetectorRefresh(slea, c)
            RecvPacketOpcode.USER_HOWLING_STORM_STACK -> PlayerHandler.UserHowlingStormStack(slea, c.player)
            RecvPacketOpcode.USER_COMPLETE_NPC_SPEECH -> PlayerHandler.UserCompleteNpcSpeech(slea, c, c.player)
            RecvPacketOpcode.COMBO_CHECK_REQUEST -> PlayerHandler.ComboCheckRequest(slea, c, c.player)
            RecvPacketOpcode.ADD_ATTACK_RESET -> {
            }
            RecvPacketOpcode.ARAN_COMBO //增加战神连击点数
            -> PlayerHandler.AranCombo(c, c.player, 5)
            RecvPacketOpcode.LOST_ARAN_COMBO //减少战神连击点数
            -> PlayerHandler.AranCombo(c, c.player, -10)
            RecvPacketOpcode.OVERLOAD_MODE_RESULT -> PlayerHandler.OverloadModeResult(slea, c, c.player)
            RecvPacketOpcode.SPECIAL_ATTACK -> PlayerHandler.specialAttack(slea, c, c.player)
            RecvPacketOpcode.SKILL_MACRO -> PlayerHandler.ChangeSkillMacro(slea, c.player)
            RecvPacketOpcode.GIVE_FAME -> PlayersHandler.GiveFame(slea, c, c.player)
            RecvPacketOpcode.TRANSFORM_PLAYER -> PlayersHandler.TransformPlayer(slea, c, c.player)
            RecvPacketOpcode.NOTE_ACTION -> PlayersHandler.Note(slea, c.player)
            RecvPacketOpcode.USE_DOOR -> PlayersHandler.UseDoor(slea, c.player)
            RecvPacketOpcode.USE_MECH_DOOR -> PlayersHandler.UseMechDoor(slea, c.player)
            RecvPacketOpcode.DAMAGE_REACTOR -> PlayersHandler.HitReactor(slea, c)
            RecvPacketOpcode.TOUCH_REACTOR -> PlayersHandler.TouchReactor(slea, c)
            RecvPacketOpcode.USE_RUNE -> PlayersHandler.UseRune(slea, c.player)
//            RecvPacketOpcode.USE_RUNE_SKILL_REQ -> PlayersHandler.UseRuneSkillReq(slea, c.player)
            RecvPacketOpcode.CLOSE_CHALKBOARD -> c.player.chalkboard = null
            RecvPacketOpcode.ITEM_GATHER -> InventoryHandler.ItemGather(slea, c)
            RecvPacketOpcode.ITEM_SORT -> InventoryHandler.ItemSort(slea, c)
            RecvPacketOpcode.ITEM_MOVE -> InventoryHandler.ItemMove(slea, c)
            RecvPacketOpcode.MOVE_BAG -> InventoryHandler.MoveBag(slea, c)
            RecvPacketOpcode.SWITCH_BAG -> InventoryHandler.SwitchBag(slea, c)
            RecvPacketOpcode.ITEM_MAKER -> ItemMakerHandler.ItemMaker(slea, c)
            RecvPacketOpcode.ITEM_PICKUP -> InventoryHandler.Pickup_Player(slea, c, c.player)
            RecvPacketOpcode.USE_CASH_ITEM //使用商城道具
            -> UseCashItemHandler.handlePacket(slea, c, c.player)
            RecvPacketOpcode.USE_ADDITIONAL_ADD_ITEM -> InventoryHandler.UseAdditionalAddItem(slea, c, c.player)
            RecvPacketOpcode.USE_ITEM //使用物品道具
            -> InventoryHandler.UseItem(slea, c, c.player)
            RecvPacketOpcode.USE_COSMETIC //使用理发卷
            -> InventoryHandler.UseCosmetic(slea, c, c.player)
            RecvPacketOpcode.USE_REDUCER //使用还原器
            -> InventoryHandler.UseReducer(slea, c, c.player)
            RecvPacketOpcode.USE_REDUCER_PRESTIGE //使用声望重置能力
            -> InventoryHandler.UseReducerPrestige(slea, c, c.player)
            RecvPacketOpcode.USE_MAGNIFY_GLASS -> InventoryHandler.UseMagnify(slea, c, c.player)
            RecvPacketOpcode.USE_CRAFTED_CUBE -> InventoryHandler.applyBlackCube(slea, c, c.player)
            RecvPacketOpcode.TOADS_HAMMER_REQUEST -> InventoryHandler.UseToadsHammerRequest(slea, c.player)
            RecvPacketOpcode.TOADS_HAMMER_HELP_REQUEST -> InventoryHandler.UseToadsHammerHelpRequest(slea, c)
            RecvPacketOpcode.USE_SCRIPTED_NPC_ITEM -> InventoryHandler.UseScriptedNPCItem(slea, c, c.player)
            RecvPacketOpcode.USE_RETURN_SCROLL -> InventoryHandler.UseReturnScroll(slea, c, c.player)
            RecvPacketOpcode.USE_UPGRADE_SCROLL, RecvPacketOpcode.USE_EXITEM_UPGRADE -> ItemScrollHandler.handlePacket(slea, c, c.player, false)
            RecvPacketOpcode.USE_FLAG_SCROLL // 这个是改变装备的状态 比如使用防暴卷什么的 但是防暴卷在 道具栏使用就检测不到
            -> ItemScrollHandler.handlePacket(slea, c, c.player, true)
            RecvPacketOpcode.USE_POTENTIAL_SCROLL, RecvPacketOpcode.USE_POTENTIAL_ADD_SCROLL, RecvPacketOpcode.USE_EQUIP_SCROLL -> ItemScrollHandler.handlePacket(slea, c, c.player, false)
            RecvPacketOpcode.USE_ADDITIONAL_ITEM //使用潜能附加印章
            -> InventoryHandler.UseAdditionalItem(slea, c, c.player)
            RecvPacketOpcode.USE_WEAPON_TEMP_OPTION -> InventoryHandler.UserWeaponTempItemOptionRequest(slea, c, c.player)
            RecvPacketOpcode.USE_SOULS_SCROLL -> InventoryHandler.UseSoulEnchanter(slea, c, c.player)
            RecvPacketOpcode.USE_SOUL_MARBLE -> InventoryHandler.UseSoulScroll(slea, c, c.player)
            RecvPacketOpcode.USE_MIRACLE_CUBE -> InventoryHandler.UseMiracleCube(slea, c.player)
            RecvPacketOpcode.USE_SUMMON_BAG -> InventoryHandler.UseSummonBag(slea, c, c.player)
            RecvPacketOpcode.USE_TREASUER_CHEST -> InventoryHandler.UseTreasureChest(slea, c, c.player)
            RecvPacketOpcode.USE_SKILL_BOOK //使用技能书
            -> {
                c.player.updateTick(slea.readInt())
                InventoryHandler.UseSkillBook(slea.readShort(), slea.readInt(), c, c.player)
            }
            RecvPacketOpcode.USE_SP_RESET //使用SP初始化卷轴
            -> {
                c.player.updateTick(slea.readInt())
                InventoryHandler.UseSpReset(slea.readShort(), slea.readInt(), c, c.player)
            }
            RecvPacketOpcode.USE_AP_RESET //使用AP初始化卷轴
            -> {
                c.player.updateTick(slea.readInt())
                InventoryHandler.UseApReset(slea.readShort(), slea.readInt(), c, c.player)
            }
            RecvPacketOpcode.USE_CATCH_ITEM -> InventoryHandler.UseCatchItem(slea, c, c.player)
            RecvPacketOpcode.USE_MOUNT_FOOD -> InventoryHandler.UseMountFood(slea, c, c.player)
            RecvPacketOpcode.REWARD_ITEM -> InventoryHandler.UseRewardItem(slea.readShort(), slea.readInt(), c, c.player)
            RecvPacketOpcode.BUY_CROSS_ITEM //购买十字猎人商店道具
            -> InventoryHandler.BuyCrossHunterItem(slea, c, c.player)
            RecvPacketOpcode.MOVE_LIFE -> MobHandler.MoveMonster(slea, c, c.player)
            RecvPacketOpcode.AUTO_AGGRO -> MobHandler.AutoAggro(slea, c.player)
            RecvPacketOpcode.MONSTER_HIT_BY_OBSTACLE_ATOM -> MobHandler.MobHitByObstacleAtom(slea, c.player)
            RecvPacketOpcode.MONSTER_HIT_BY_MOB -> MobHandler.MobHitByMob(slea, c.player)
            RecvPacketOpcode.MONSTER_BOMB -> MobHandler.MonsterBomb(slea.readInt(), c.player)
            RecvPacketOpcode.MONSTER_BOMB_COLLISION_GROUP -> {
            }
            RecvPacketOpcode.MONSTER_TIME_BOMB_END -> MobHandler.MobTimeBombEnd(slea, c.player)
            RecvPacketOpcode.MONSTER_ESCORT_COLLISION -> MobHandler.MobEscortCollision(slea, c.player)
            RecvPacketOpcode.MONSTER_SPECIAL_SKILL -> MobHandler.MonsterSpecialSkill(slea, c.player)
            RecvPacketOpcode.NPC_SHOP -> NPCHandler.NPCShop(slea, c, c.player)
            RecvPacketOpcode.NPC_TALK -> NPCHandler.NPCTalk(slea, c, c.player)
            RecvPacketOpcode.NPC_TALK_MORE -> NPCHandler.NPCMoreTalk(slea, c)
            RecvPacketOpcode.NPC_ACTION -> NPCHandler.NPCAnimation(slea, c)
            RecvPacketOpcode.QUEST_ACTION //任务操作
            -> NPCHandler.QuestAction(slea, c, c.player)
            RecvPacketOpcode.REISSUE_MEDAL //重新领取勋章
            -> PlayerHandler.ReIssueMedal(slea, c, c.player)
            RecvPacketOpcode.STORAGE //仓库操作
            -> NPCHandler.Storage(slea, c, c.player)
            RecvPacketOpcode.GENERAL_CHAT -> if (c.player != null && c.player.map != null) {
                c.player.updateTick(slea.readInt())
                ChatHandler.GeneralChat(slea.readMapleAsciiString(), slea.readByte(), c, c.player)
            }
            RecvPacketOpcode.PARTYCHAT -> ChatHandler.Others(slea, c, c.player)
            RecvPacketOpcode.WHISPER -> ChatHandler.Whisper_Find(slea, c)
            RecvPacketOpcode.MESSENGER -> ChatHandler.Messenger(slea, c)
            RecvPacketOpcode.SHOW_LOVE_RANK -> ChatHandler.ShowLoveRank(slea, c)
            RecvPacketOpcode.SPAWN_ARROWS_TURRET -> PlayerHandler.SpawnArrowsTurret(slea, c, c.player)
            RecvPacketOpcode.USE_GROWTH_HELPER_REQUEST -> PlayerHandler.UserGrowthHelperRequest(slea, c, c.player)
            RecvPacketOpcode.RUN_SCRIPT -> PlayerHandler.RunScript(slea, c)
            RecvPacketOpcode.ENTER_STARTPLANET -> InterServerHandler.EnterMTS(c, c.player)
        //            case GAME_EXIT:
        //                PlayerHandler.GameExit(c);
        //                break;
            RecvPacketOpcode.TRACK_FLAMES -> PlayerHandler.showTrackFlames(slea, c, c.player)
            RecvPacketOpcode.AUTO_ASSIGN_AP -> StatsHandling.AutoAssignAP(slea, c, c.player)
            RecvPacketOpcode.DISTRIBUTE_AP -> StatsHandling.DistributeAP(slea, c, c.player)
            RecvPacketOpcode.DISTRIBUTE_SP //分配普通技能点
            -> StatsHandling.DistributeSP(slea, c, c.player)
            RecvPacketOpcode.DISTRIBUTE_HYPER_AP -> {
                c.player.updateTick(slea.readInt())
                StatsHandling.DistributeHyperSP(slea.readInt(), c, c.player, true)
            }
            RecvPacketOpcode.DISTRIBUTE_HYPER_SP //分配超级技能点
            -> {
                c.player.updateTick(slea.readInt())
                StatsHandling.DistributeHyperSP(slea.readInt(), c, c.player, false)
            }
            RecvPacketOpcode.RESET_HYPER_SP //初始化超级技能点
            -> StatsHandling.ResetHyperSP(slea, c, c.player)
            RecvPacketOpcode.RESET_HYPER_AP -> StatsHandling.ResetHyperAP(slea, c, c.player)
            RecvPacketOpcode.PLAYER_INTERACTION -> PlayerInteractionHandler.PlayerInteraction(slea, c, c.player)
            RecvPacketOpcode.GUILD_OPERATION -> GuildHandler.Guild(slea, c)
            RecvPacketOpcode.DENY_GUILD_REQUEST -> {
                slea.skip(1)
                GuildHandler.DenyGuildRequest(slea.readMapleAsciiString(), c)
            }
            RecvPacketOpcode.GUILD_APPLY -> GuildHandler.GuildApply(slea, c)
            RecvPacketOpcode.ACCEPT_GUILD_APPLY -> GuildHandler.AcceptGuildApply(slea, c)
            RecvPacketOpcode.DENY_GUILD_APPLY -> GuildHandler.DenyGuildApply(slea, c)
            RecvPacketOpcode.TOWER_RANK_REQUEST -> PlayersHandler.getTowerRankRequest(slea, c, c.player)
        //            case ALLIANCE_OPERATION:
        //                AllianceHandler.HandleAlliance(slea, c, false);
        //                break;
        //            case DENY_ALLIANCE_REQUEST:
        //                AllianceHandler.HandleAlliance(slea, c, true);
        //                break;
            RecvPacketOpcode.QUICK_MOVE //快速移动
            -> NPCHandler.OpenQuickMoveNpc(slea, c)
            RecvPacketOpcode.BBS_OPERATION -> BBSHandler.BBSOperation(slea, c)
            RecvPacketOpcode.SELECT_JAGUAR -> PlayerHandler.selectJaguar(slea, c, c.player)
            RecvPacketOpcode.GIVE_KSPSYCHIC -> PlayerHandler.showKSPsychicGrabHanlder(slea, c, c.player)
            RecvPacketOpcode.ATTACK_KSPSYCHIC -> PlayerHandler.showKSPsychicAttackHanlder(slea, c, c.player)
            RecvPacketOpcode.CANCEL_KSPSYCHIC -> PlayerHandler.showKSPsychicReleaseHanlder(slea, c, c.player)
            RecvPacketOpcode.GIVE_KSULTIMATE -> PlayerHandler.showGiveKSUltimate(slea, c, c.player)
            RecvPacketOpcode.ATTACK_KSULTIMATE -> PlayerHandler.showAttackKSUltimate(slea, c, c.player)
            RecvPacketOpcode.MIST_KSULTIMAT -> PlayerHandler.showKSMonsterEffect(slea, c, c.player)
            RecvPacketOpcode.CANCEL_KSULTIMATE -> PlayerHandler.showCancelKSUltimate(slea, c, c.player)
            RecvPacketOpcode.PSYCHIC_OVER_REQUEST -> PlayerHandler.PsychicOverRequest(slea, c, c.player)
            RecvPacketOpcode.PARTY_OPERATION -> PartyHandler.PartyOperation(slea, c)
            RecvPacketOpcode.DENY_PARTY_REQUEST -> PartyHandler.DenyPartyRequest(slea, c)
            RecvPacketOpcode.ALLOW_PARTY_INVITE -> PartyHandler.AllowPartyInvite(slea, c)
            RecvPacketOpcode.BUDDYLIST_MODIFY -> BuddyListHandler.BuddyOperation(slea, c)
        //            case CYGNUS_SUMMON:
        //                UserInterfaceHandler.CygnusSummon_NPCRequest(c);
        //                break;
        //            case SHIP_OBJECT:
        //                UserInterfaceHandler.ShipObjectRequest(slea.readInt(), c);
        //                break;
            RecvPacketOpcode.BUY_CS_ITEM //购买商城道具
            -> BuyCashItemHandler.BuyCashItem(slea, c, c.player)
            RecvPacketOpcode.COUPON_CODE //用兑换码兑换商城道具
            -> CouponCodeHandler.handlePacket(slea, c, c.player)
            RecvPacketOpcode.CS_UPDATE //刷新点卷
            -> CashShopOperation.CSUpdate(c)
            RecvPacketOpcode.SEND_CS_GIFI //商城送礼
            -> BuyCashItemHandler.商城送礼(slea, c, c.player)
            RecvPacketOpcode.OPEN_AVATAR_RANDOM_BOX -> {
            }
        //            case TOUCHING_MTS:
        //                MTSOperation.MTSUpdate(MTSStorage.getInstance().getCart(c.getPlayer().getId()), c);
        //                break;
        //            case MTS_TAB:
        //                MTSOperation.MTSOperation(slea, c);
        //                break;
            RecvPacketOpcode.USE_POT -> ItemMakerHandler.UsePot(slea, c)
            RecvPacketOpcode.CLEAR_POT -> ItemMakerHandler.ClearPot(slea, c)
            RecvPacketOpcode.FEED_POT -> ItemMakerHandler.FeedPot(slea, c)
            RecvPacketOpcode.CURE_POT -> ItemMakerHandler.CurePot(slea, c)
            RecvPacketOpcode.REWARD_POT -> ItemMakerHandler.RewardPot(slea, c)
            RecvPacketOpcode.MOVE_LITTLEWHITE -> SummonHandler.MoveLittleWhite(slea, c.player)
            RecvPacketOpcode.DAMAGE_SUMMON -> SummonHandler.DamageSummon(slea, c.player)
            RecvPacketOpcode.MOVE_SUMMON -> SummonHandler.MoveSummon(slea, c.player)
            RecvPacketOpcode.MOVE_DRAGON //龙龙移动
            -> SummonHandler.MoveDragon(slea, c.player)
            RecvPacketOpcode.DRAGON_FLY //龙飞行
            -> SummonHandler.DragonFly(slea, c.player)
            RecvPacketOpcode.SUB_SUMMON -> SummonHandler.SubSummon(slea, c.player)
            RecvPacketOpcode.SUMMON_MAGIC_ALTAR -> SummonHandler.SummonedMagicAltar(slea, c, c.player)
            RecvPacketOpcode.SUMMON_REMOVE -> SummonHandler.RemoveSummon(slea, c)
            RecvPacketOpcode.SUMMON_SARAH_ACTION -> SummonHandler.SummonedSarahAction(slea, c, c.player)
            RecvPacketOpcode.SUMMON_JAVELIN_ACTION -> SummonHandler.SummonedJavelinAction(slea, c, c.player)
            RecvPacketOpcode.SPAWN_PET -> PetHandler.SpawnPet(slea, c, c.player)
            RecvPacketOpcode.PET_AUTO_BUFF -> PetHandler.Pet_AutoBuff(slea, c, c.player)
            RecvPacketOpcode.MOVE_PET -> PetHandler.MovePet(slea, c.player)
            RecvPacketOpcode.PET_CHAT -> PetHandler.PetChat(slea, c, c.player)
            RecvPacketOpcode.PET_COMMAND -> PetHandler.PetCommand(slea, c, c.player)
            RecvPacketOpcode.PET_FOOD -> PetHandler.PetFood(slea, c, c.player)
            RecvPacketOpcode.PET_LOOT -> InventoryHandler.Pickup_Pet(slea, c, c.player)
            RecvPacketOpcode.PET_AUTO_POT -> PetHandler.Pet_AutoPotion(slea, c, c.player)
            RecvPacketOpcode.PET_EXCEPTION_LIST -> PetHandler.PetExcludeItems(slea, c, c.player)
            RecvPacketOpcode.PET_AOTO_EAT -> {
                slea.skip(4)
                PetHandler.PetFood(slea, c, c.player)
            }
            RecvPacketOpcode.ALLOW_PET_LOOT //是否允许宠物捡取道具
            -> PetHandler.AllowPetLoot(slea, c, c.player)
            RecvPacketOpcode.ALLOW_PET_AOTO_EAT //是否允许宠物自动喂食
            -> PetHandler.AllowPetAutoEat(slea, c, c.player)
            RecvPacketOpcode.USE_OPTION_CHANGE_REQUEST -> UseHammerHandler.GoldHammerResponse(slea, c)
            RecvPacketOpcode.DUEY_ACTION -> DueyHandler.DueyOperation(slea, c)
            RecvPacketOpcode.USE_HIRED_MERCHANT -> HiredMerchantHandler.UseHiredMerchant(c, true)
            RecvPacketOpcode.MERCH_ITEM_STORE -> HiredMerchantHandler.MerchantItemStore(slea, c)
            RecvPacketOpcode.FISHING -> HiredFisherHandler.UseHiredFisher(slea, c.player)
            RecvPacketOpcode.CANCEL_DEBUFF -> {
                // Ignore for now
            }
            RecvPacketOpcode.REPAIR -> NPCHandler.repair(slea, c)
            RecvPacketOpcode.REPAIR_ALL -> NPCHandler.repairAll(c)
            RecvPacketOpcode.OWL -> InventoryHandler.Owl(slea, c)
            RecvPacketOpcode.OWL_WARP -> InventoryHandler.OwlWarp(slea, c)
            RecvPacketOpcode.USE_OWL_MINERVA -> InventoryHandler.OwlMinerva(slea, c)
            RecvPacketOpcode.RPS_GAME -> NPCHandler.RPSGame(slea, c)
//            RecvPacketOpcode.UPDATE_QUEST -> NPCHandler.UpdateQuest(slea, c)
//            RecvPacketOpcode.USE_ITEM_QUEST -> NPCHandler.UseItemQuest(slea, c)
            RecvPacketOpcode.FOLLOW_REQUEST -> PlayersHandler.FollowRequest(slea, c)
            RecvPacketOpcode.AUTO_FOLLOW_REPLY, RecvPacketOpcode.FOLLOW_REPLY -> PlayersHandler.FollowReply(slea, c)
            RecvPacketOpcode.RING_ACTION -> PlayersHandler.RingAction(slea, c)
        //            case REQUEST_FAMILY:
        //                FamilyHandler.RequestFamily(slea, c);
        //                break;
        //            case OPEN_FAMILY:
        //                FamilyHandler.OpenFamily(slea, c);
        //                break;
        //            case FAMILY_OPERATION:
        //                FamilyHandler.FamilyOperation(slea, c);
        //                break;
        //            case DELETE_JUNIOR:
        //                FamilyHandler.DeleteJunior(slea, c);
        //                break;
        //            case DELETE_SENIOR:
        //                FamilyHandler.DeleteSenior(slea, c);
        //                break;
        //            case USE_FAMILY:
        //                FamilyHandler.UseFamily(slea, c);
        //                break;
        //            case FAMILY_PRECEPT:
        //                FamilyHandler.FamilyPrecept(slea, c);
        //                break;
        //            case FAMILY_SUMMON:
        //                FamilyHandler.FamilySummon(slea, c);
        //                break;
        //            case ACCEPT_FAMILY:
        //                FamilyHandler.AcceptFamily(slea, c);
        //                break;
            RecvPacketOpcode.SOLOMON -> PlayersHandler.Solomon(slea, c)
            RecvPacketOpcode.GACH_EXP -> PlayersHandler.GachExp(slea, c)
            RecvPacketOpcode.PARTY_SEARCH_START -> PartyHandler.MemberSearch(slea, c)
            RecvPacketOpcode.PARTY_SEARCH_STOP -> PartyHandler.PartySearch(slea, c)
            RecvPacketOpcode.EXPEDITION_LISTING -> PartyHandler.PartyListing(slea, c)
            RecvPacketOpcode.EXPEDITION_OPERATION -> PartyHandler.Expedition(slea, c)
            RecvPacketOpcode.USE_TELE_ROCK -> InventoryHandler.TeleRock(slea, c)
            RecvPacketOpcode.PAM_SONG -> InventoryHandler.PamSong(slea, c)
            RecvPacketOpcode.REPORT -> PlayersHandler.Report(slea, c)
            RecvPacketOpcode.REMOTE_STORE //雇佣商人遥控器
            -> HiredMerchantHandler.RemoteStore(slea, c)
            RecvPacketOpcode.SHIKONGJUAN //超时空券
            -> PlayerHandler.UseChronosphere(slea, c, c.player)
            RecvPacketOpcode.CONTISTATE -> UserInterfaceHandler.ShipObjectRequest(slea.readInt(), c)
            RecvPacketOpcode.PLAYER_UPDATE //玩家数据更新
            -> PlayerHandler.PlayerUpdate(c, c.player)
            RecvPacketOpcode.CHANGE_MARKET_MAP -> PlayerHandler.ChangeMarketMap(slea, c, c.player)
            RecvPacketOpcode.DEL_TEACH_SKILL -> PlayerHandler.DelTeachSkill(slea, c, c.player)
            RecvPacketOpcode.SET_TEACH_SKILL //传授技能
            -> PlayerHandler.SetTeachSkill(slea, c, c.player)
            RecvPacketOpcode.SET_CHAR_CASH -> PlayerHandler.showPlayerCash(slea, c)
            RecvPacketOpcode.OPEN_WORLDMAP -> c.announce(MaplePacketCreator.openWorldMap())
            RecvPacketOpcode.SAVE_DAMSKIN -> PlayerHandler.SaveDamageSkin(slea, c.player)
            RecvPacketOpcode.CHANGE_DAMSKIN -> PlayerHandler.ChangeDamageSkin(slea, c.player)
//            RecvPacketOpcode.DELETE_DAMSKIN -> PlayerHandler.DeleteDamageSkin(slea, c.player)
            RecvPacketOpcode.USE_HAMMER //使用金锤子
            -> UseHammerHandler.UseHammer(slea, c)
            RecvPacketOpcode.HAMMER_RESPONSE //使用金锤子
            -> UseHammerHandler.HammerResponse(slea, c)
            RecvPacketOpcode.BATTLE_STATISTICS -> PlayerHandler.startBattleStatistics(slea, c)
            RecvPacketOpcode.MEMORY_SKILL_CHOOSE  //装备复制技能
            -> PhantomMemorySkill.MemorySkillChoose(slea, c)
            RecvPacketOpcode.MEMORY_SKILL_CHANGE //删除选择技能
            -> PhantomMemorySkill.MemorySkillChange(slea, c)
            RecvPacketOpcode.MEMORY_SKILL_OBTAIN //封印之瞳
            -> PhantomMemorySkill.MemorySkillObtain(slea, c)
            RecvPacketOpcode.PLAYER_VIEW_RANGE -> {
                val by2 = slea.readByte()
                if (by2.toInt() == 1) {
                    c.sendEnableActions()
                }
            }
            RecvPacketOpcode.CHANGE_POTENTIAL // 神之子更改武器潜能
            -> ItemScrollHandler.ChangeWeaponPotential(slea, c, c.player)
            RecvPacketOpcode.CHANGE_POTENTIAL_WP -> ItemScrollHandler.ChangeWeaponPotential_WP(slea, c, c.player)
            RecvPacketOpcode.USE_TEMPEST_BLADES //使用剑刃之壁
            -> PlayerHandler.useTempestBlades(slea, c, c.player)
            RecvPacketOpcode.UNKNOWN_168 ->
                /*
                 * 68 01
                 * 09 00 31 32 33 31 32 33 31 32 33 - 角色名字
                 */
                c.announce(MaplePacketCreator.sendUnkPacket1FC())
            RecvPacketOpcode.QUICK_BUY_CS_ITEM //快速扩充和购买商城道具
            -> PlayerHandler.quickBuyCashShopItem(slea, c, c.player)
            RecvPacketOpcode.SYSTEM_PROCESS_LIST -> SystemProcess.SystemProcess(slea, c, c.player)
            RecvPacketOpcode.FAMILIAR_OPERATION -> PlayerHandler.useFamiliarCard(slea, c, c.player)
            RecvPacketOpcode.SOUL_MODE -> PlayerHandler.updateSoulEffect(slea, c, c.player)
            RecvPacketOpcode.USE_TOWERCHAIR_SETTING -> PlayerHandler.UseTowerChairSetting(slea, c, c.player)
            RecvPacketOpcode.OPEN_MAPLE_UNION_REQUEST -> PlayerHandler.OpenMapleUnionRequest(slea, c.player)
            RecvPacketOpcode.VMATRIX_MAKE_REQUEST -> PlayerHandler.VCoreOperation(slea, c.player)
            RecvPacketOpcode.VMATRIX_HELP_REQUEST -> PlayerHandler.VmatrixHelpRequest(slea, c.player)
            RecvPacketOpcode.EVENT_REVIVE_REQUEST -> PlayerHandler.EventReviveRequest(c.player, slea.readByte().toInt())
            RecvPacketOpcode.FORCE_TARGET_REQUEST -> PlayerHandler.ForceTargetRequest(slea, c, c.player)
            RecvPacketOpcode.CRYSTAL_CHARGE -> PlayerHandler.CrystalCharge(slea, c)
            RecvPacketOpcode.SIGNIN_OPERATION -> PlayerHandler.openSigin(slea, c, c.player)
            RecvPacketOpcode.RW_MULTI_CHARGE_CANCEL_REQUEST -> PlayerHandler.MultiChargeCancelRequest(slea, c, c.player)
            RecvPacketOpcode.MULTI_SKILL_ATTACK_REQUEST -> PlayerHandler.MulitSkillAttackRequest(slea, c.player)
            RecvPacketOpcode.REMOTE_DICE_REQUEST -> PlayerHandler.RemoteDiceResult(slea, c, c.player)
            RecvPacketOpcode.MULTI_SKILL_CHARGE_REQUEST -> PlayerHandler.MultiSkillChargeRequest(slea, c.player)
            RecvPacketOpcode.GIVE_SPOTLIGHT_BUFF -> PlayerHandler.GiveSpotlightBuff(slea, c, c.player)
            RecvPacketOpcode.MAPLE_UNION_REQUEST -> PlayerHandler.MapleUnionRequest(slea, c.player)
            RecvPacketOpcode.ILLIUM_JAVE_LIN -> PlayerHandler.IlliumJavelin(slea, c, c.player)
            RecvPacketOpcode.POTION_POT_USE -> PotionPotHandler.PotionPotUse(slea, c, c.player)
            RecvPacketOpcode.POTION_POT_ADD -> PotionPotHandler.PotionPotAdd(slea, c, c.player)
            RecvPacketOpcode.POTION_POT_MODE -> PotionPotHandler.PotionPotMode(slea, c, c.player)
            RecvPacketOpcode.POTION_POT_INCR -> PotionPotHandler.PotionPotIncr(slea, c, c.player)
            RecvPacketOpcode.APPLY_HYUNCUBE -> InventoryHandler.applyHyunCube(slea, c, c.player)
            RecvPacketOpcode.USER_DAZZLE_HIT -> PlayerHandler.UserDazzleHit(slea, c, c.player)
            RecvPacketOpcode.CHANGE_ZERO_LOOK -> PlayerHandler.changeZeroLook(slea, c, c.player, false)
            RecvPacketOpcode.ZERO_SHARE_CASH_EQUIP_PART -> PlayerHandler.ZeroShareCashEquipPart(slea, c, c.player)
            RecvPacketOpcode.CHANGE_ZERO_LOOK_END -> PlayerHandler.changeZeroLook(slea, c, c.player, true)
            RecvPacketOpcode.EXTRA_ATTACK -> PlayerHandler.ExtraAttack(slea, c, c.player)
            RecvPacketOpcode.SHOW_FIREWALL_REQUEST -> PlayerHandler.spawnSpecial(slea, c, c.player)
            RecvPacketOpcode.MOVE_ENERGY -> PlayerHandler.MoveEnergyBall(slea, c)
            RecvPacketOpcode.HIDDEN_TAIL_ADN_EAR -> c.player?.hiddenTailAndEar(slea.readInt())
            RecvPacketOpcode.FORCEATOM_COLLISION -> PlayerHandler.absorbingDF(slea, c, c.player)
            RecvPacketOpcode.USER_TRUMP_SKILL_ACTION_REQUEST -> PlayerHandler.UserTrumpSkillActionRequest(slea, c.player)
            RecvPacketOpcode.DOT_HEAL_HP_REQUEST -> PlayerHandler.DotHealHPRequest(c.player)
            RecvPacketOpcode.EFFECT_SWITCH -> PlayerHandler.effectSwitch(slea, c)
            RecvPacketOpcode.CALL_FRIENDS -> PlayerHandler.callFriends(slea, c, c.player)
            RecvPacketOpcode.SELECT_CHAIR -> PlayerHandler.selectChair(slea, c, c.player)
            RecvPacketOpcode.TAP_JOY_RESPONSE -> UseCashItemHandler.TapJoyResponse(slea, c.player)
            RecvPacketOpcode.TAP_JOY_DONE -> UseCashItemHandler.TapJoyDone(slea, c.player)
            RecvPacketOpcode.TAP_JOY_NEXT_STAGE -> UseCashItemHandler.TapJoyNextStage(slea, c.player)
            RecvPacketOpcode.CRYSTAL_CONNECT -> PlayerHandler.CrystalConnect(slea, c, c.player)
            else -> {
//                log.info("[未处理封包] Recv " + header.toString() + " [" + HexTool.getOpcodeToString(header.value.toInt()) + "]")
            }
        }
    }
}